<?php
session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	header("location:../login_r.php");

}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
         <link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />
        
<script type="text/javascript" src="../javascripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
		mode : "textareas",
		theme : "advanced",
		plugins : "pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak,restoredraft",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

		// Style formats
		style_formats : [
			{title : 'Bold text', inline : 'b'},
			{title : 'Red text', inline : 'span', styles : {color : '#ff0000'}},
			{title : 'Red header', block : 'h1', styles : {color : '#ff0000'}},
			{title : 'Example 1', inline : 'span', classes : 'example1'},
			{title : 'Example 2', inline : 'span', classes : 'example2'},
			{title : 'Table styles'},
			{title : 'Table row 1', selector : 'tr', classes : 'tablerow1'}
		],

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
	
		function toggleEditor(id) {
		if (!tinyMCE.get(id))
			tinyMCE.execCommand('mceAddControl', false, id);
		else
			tinyMCE.execCommand('mceRemoveControl', false, id);
	}
</script>


<? 

$type = $_GET['type'];
//switch o if?
	//Makabayan Section
	if($type == 'makabayan'):
		$typeCat = 'viewMakabayan';
		$typeCategory = 'Makabayan';
		//Filipino Section
		elseif($type == 'filipino'):
		$typeCat = 'viewFilipino';
		$typeCategory = 'Filipino';
		//English Section
		elseif($type == 'english'):
		$typeCat = 'viewEnglish';
		$typeCategory = 'English';
		//Math Section
		elseif($type == 'math'):
		$typeCat = 'viewMath';
		$typeCategory = 'Math';
		//Science Section
		elseif($type == 'science'):
		$typeCat = 'viewScience';
		$typeCategory = 'Science';
		//Others Section
		elseif($type == 'others'):

		$typeCat = 'viewOthers';
		$typeCategory = 'Others';

endif;


if(isset($_POST['prev'])):

	$topTitle = $_POST['topTitle'];
	$topContent = $_POST['topContent'];
	$topDate = date("F j, Y H:i:s");


	print '
                    <table width="700" border="0" id="cform">

                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                        <td class="extra">Title: '.$topTitle.'</td><td align="right" class="extra">'.$topDate.'</td>
                      </tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>

                      <tr>
                        <td><label>
                          '.$topContent.'
                        </label></td>
                      </tr>
                    </table><br /><br />
                        ';
	
	

elseif(isset($_POST['save'])):

		$userid = $_SESSION['curuser'];
		$topTitle = $_POST['topTitle'];
		$topContent = $_POST['topContent'];		
		$createby = $_SESSION['us'];
		$topDate = date("F j, Y H:i:s");
		
		 $result = mysql_query("SELECT origWord,replaceWord  FROM tblreplace") or die(mysql_error()); 
   		

    while($row = mysql_fetch_assoc($result))
    {		$repWord = $row['replaceWord'];
			$origWord = $row['origWord'];
          $topTitle = str_ireplace($row['origWord'], $row['replaceWord'], $topTitle);
		  $topContent = str_ireplace($row['origWord'], $row['replaceWord'],  $topContent);
		
    }  
   
	 if($topTitle){
			$resInsert = mysql_query("INSERT INTO `tblreplace`(`origWord`,`replaceWord`,`creatorName`,`date`,`fieldName`)
									 VALUES('$origWord','$repWord','$userid',NOW(),'[Forum] - Topic Title')") or die(mysql_error());  
		  }
	if($topContent){
			$resInsert = mysql_query("INSERT INTO `tblreplace`(`origWord`,`replaceWord`,`creatorName`,`date`,`fieldName`)
									 VALUES('$origWord','$repWord','$userid',NOW(),'[Forum] - Topic Content')") or die(mysql_error());  
		  }

	if($topContent==NULL && $topTitle == NULL){
		
		
		print '
		
		<script type="text/javascript">
		
		alert("Please complete the fields.");
		window.location = "createTopic.php?type='.$type.'";
		</script>
		
		
		';
		
	}
else{
		
			
		$ins = mysql_query("INSERT INTO tblfrtopic (topictitle,
												topicontent,
												topicdate,
												createdby,
												createdbyid,
												category) VALUES('$topTitle',
												'$topContent',
												'$topDate',
												'$createby',
												'$userid',
												'$type')") or die (mysql_error());
		
			if($type=='makabayan')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewMakabayan.php";
			</script>
			
			
			';
			}
			
			else if($type=='filipino')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewFilipino.php";
			</script>
			
			
			';
			}
			else if($type=='english')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewEnglish.php";
			</script>
			
			
			';
			}
			else if($type=='math')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewMath.php";
			</script>
			
			
			';
			}
				else if($type=='science')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewScience.php";
			</script>
			
			
			';
			}
		
				else if($type=='others')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewOthers.php";
			</script>
			
			
			';
			}
		
		
		
		
		}
						
      	             
endif;	
?>


<body>
<div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
    <p> </p>
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left" class="date"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
           <!-- <div id="chef_ind">open chef -->
        <div id="welcome"> <!--open welcome -->
               <!-- <h2 class="guilded"></h2> -->
        </div> <!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>
  </div>
        
      <!--</div>close left -->

      <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3_students"><h2>Forum</h2> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg1"><!--open booking -->
        <div align="center" class="mainbox">

                  <form id="form2" name="form2" method="post" action="">
                    <table width="600" border="0">
                    <tr>
                        <td colspan="6">
                    <b>Forum</b>  <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="<? print $typeCat; ?>.php"><? print $typeCategory; ?></a>  <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="#"><strong>New Create Topic</strong></a>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" background="catbg.png" colspan="5" class="cat"><? print $topTitle; ?></td>
                    </tr>
                    <tr>
                  <td height="23" class="label">POST A NEW TOPIC</td>
                	</tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                
				
			
			
                        <td class="extra"><b>Title:</b> <input name="topTitle" type="text" id="topTitle" size="113" value="<? print $topTitle; ?>" /></td>
                	
                     
                    </tr>
                      <tr>
                        <td>&nbsp; </td>
                      </tr>
                      <tr>
                        <td><textarea id="topContent" name="topContent" rows="15" cols="80" style="width:70%">
                          <? print $topContent; ?>
                          </textarea>
                          
<!-- Some integration calls -->
<!--		<a href="javascript:;" onmousedown="tinyMCE.get('elm1').show();">[Show]</a>
		<a href="javascript:;" onmousedown="tinyMCE.get('elm1').hide();">[Hide]</a>
		<a href="javascript:;" onmousedown="tinyMCE.get('elm1').execCommand('Bold');">[Bold]</a>
		<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').getContent());">[Get contents]</a>
		<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getContent());">[Get selected HTML]</a>
		<a href="javascript:;" onmousedown="alert(tinyMCE.get('elm1').selection.getContent({format : 'text'}));">[Get selected text]</a>
		<a href="javascript:;" onmousedown=="alert(tinyMCE.get('elm1').selection.getNode().nodeName);">[Get selected element]</a>
		<a href="javascript:;" onmousedown="tinyMCE.execCommand('mceInsertContent',false,'<b>Hello world!!</b>');">[Insert HTML]</a>
		<a href="javascript:;" onmousedown="tinyMCE.execCommand('mceReplaceContent',false,'<b>{$selection}</b>');">[Replace selection]</a>-->
                          </td>
                      </tr>
                      <tr>
                        <td align="center"><label>
                         <input value='Back' type='button' id='btnb' onclick='history.go(-1); return false;' />  <!--<input type="button" name="Submit" value="toggle editor" onclick="javascript:toggleEditor('elm1');" />--> 
                          <input type="submit" name="save" id="save" value="Submit" />
                        </label></td>
                      </tr>
                    </table>
            </form>    
             </div>   
</div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>



	

